import cv2
# 打开对应的摄像头
if __name__ == "__main__":
    cap1 = cv2.VideoCapture(0)
    # 获取捕获的分辨率
    # propId可以直接写数字，也可以用OpenCV的符号表示
    width, height = cap1.get(3), cap1.get(4)
    print(width, height)

    # 以原分辨率的一倍来捕获
    cap1.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
    cap1.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
    i = 0

    while True:
        ret1, frame1 = cap1.read()
        k = cv2.waitKey(1)
        if k == 27:
            break
        elif k == ord('s'):
            cv2.imwrite('./right' + str(i) + '.jpg', frame1)
            i += 1
        cv2.imshow("right", frame1)
    cap1.release()
    cv2.destroyAllWindows()